import Vue from 'vue'
import moment from 'moment'
// 注册日期过滤器
Vue.filter('date', (dateStr, format = 'YYYY-MM-DD HH:mm:ss') => {
  return moment(dateStr).format(format)
})
export default {
  data () {
    return {
      // 商品列表数据
      goodsList: [],
      total: 1,
      pagenum: 1
    }
  },
  created () {
    // 获取商品列表
    this.getGoodsList()
  },
  methods: {
    // 获取商品列表
    async getGoodsList (pagenum = 1) {
      const res = await this.$axios.get('goods', {
        params: {
          query: '',
          pagenum,
          pagesize: 4
        }
      })
      this.goodsList = res.data.data.goods
      this.total = res.data.data.total
      this.pagenum = res.data.data.pagenum
    },
    // 分页切换
    pageChange (currentPage) {
      this.getGoodsList(currentPage)
    }
  }
}
